package calao.util;

/** A period of time.
 */
public class TimePeriod {

	public final static int SECOND = 1000;
	public final static int MINUTE = 60*SECOND;
	public final static int HOUR = 60*MINUTE;
	public final static int DAY = 24*HOUR;
	public final static int WEEK = 7*DAY;
	
	long start;
	long end;
	
	/** Checks whether this period overlaps another period.
	 */
	public boolean overlaps(TimePeriod period) {
		if (period.start<start) return period.end>start;
		else return period.start<end;
	}
	
	public TimePeriod(long start, long end)
	{
		if (!(start<end)) throw new IllegalArgumentException();
		this.start = start;
		this.end = end;
	}
	
	public long length()
	{
		return end-start;
	}
	
	public long getStartTime() {
		return start;
	}
	
	public long getEndTime() {
		return end;
	}
	
	public boolean contains(long time)
	{
		return start<=time && time<end;
	}
	
}
